package cn.iocoder.yudao.module.crm.dal.mysql.tasktype;

import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.crm.controller.admin.tasktype.vo.tasktypeapprover.TaskTypeApproverDetail;
import cn.iocoder.yudao.module.crm.dal.dataobject.tasktype.TaskTypeApproverDO;
import cn.iocoder.yudao.module.crm.dal.dataobject.tasktype.TaskTypeAssigneeDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * CRM 任务单类型审批人 Mapper
 *
 * @author 广州氪量
 */
@Mapper
public interface TaskTypeApproverMapper extends BaseMapperX<TaskTypeApproverDO> {
    default List<TaskTypeApproverDO> selectAllByTaskTypeId(Long taskTypeId) {
        return selectList(TaskTypeApproverDO::getTaskTypeId, taskTypeId);
    }

    default List<TaskTypeApproverDO> getByTaskTypeId(Long taskTypeId){
        return selectList(TaskTypeApproverDO::getTaskTypeId,taskTypeId);
    }

    default void insertBatchByTaskTypeId(List<TaskTypeApproverDetail> approver, Long taskTypeId){
        approver.forEach(item -> {
            TaskTypeApproverDO taskTypeApprover =  new TaskTypeApproverDO();
            taskTypeApprover.setTaskTypeId(taskTypeId);
            taskTypeApprover.setUserId(item.getUserId());
            taskTypeApprover.setReviewOrder(item.getReviewOrder());
            insert(taskTypeApprover);
        });
    }

    default void deleteBatchByTaskTypeId(Long taskTypeId){
        delete(new LambdaQueryWrapperX<TaskTypeApproverDO>()
                .eq(TaskTypeApproverDO::getTaskTypeId, taskTypeId));
    }

    default List<TaskTypeApproverDO> selectListByTaskTypeId(Long taskTypeId){
        return selectList(TaskTypeApproverDO::getTaskTypeId, taskTypeId);
    }
}